<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*,java.text.SimpleDateFormat,com.javabean.*,com.model.*,java.util.Date,
java.text.SimpleDateFormat,com.model.*;"
    pageEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../jqueryui/css/smoothness/jquery-ui-1.10.0.custom.min.css"/>
<script src="../jqueryui/js/jquery-1.9.0.js"></script>
<script src="../jqueryui/js/jquery-ui-1.10.3.custom.js"></script>
<script src="../jqueryui/development-bundle/ui/i18n/jquery.ui.datepicker-zh-CN.js"></script>
<title>会议室预约</title>

<style>
	body{
		background-color:#FFFFFF;
		width:100%;
		height:100%;
		margin:0px;
		padding:0px;
		}
	.tr{
		background-color:#FFFFFF;
		border:0px;
	}
	.td{
		width:10%;
		border:0px;
	}
</style>

<script>
function save(){
	if(document.form.ConnectorName.value == null || document.form.ConnectorName.value == ""){
		alert("联系人必须填写");
		document.form.ConnectorName.focus();
		return;
	}
	else if(document.form.ConnectMeans.value == null || document.form.ConnectMeans.value == ""){
		alert("联系方式必须填写");
		document.form.ConnectMeans.focus();
		return;
	}
	else if(confirm("确认保存？")){
		document.form.submit();		
	}
}
function save2(){
	window.open("RL2.jsp","_self");
}

$(function(){
	<%
	User user=(User)request.getSession(true).getAttribute("user");
	boolean show=(user==null)?false:true;
	String userName="";
	String userDepartment="";
	System.out.print("show:"+show);
	if(show){
		userName = ((User) request.getSession(true).getAttribute("user")).getUserName();
		userDepartment = ((User) request.getSession(true).getAttribute("user")).getUserDepartment();
		  
	}
	%>
	if(<%=show%>){
		$("#meetingList").css("height","50%");
		$("#bookMes").show();
		$("#login").hide();
	}
	else{
		$("#meetingList").css("height","100%");
		$("#bookMes").hide();
		$("#login").show();
		
	}
});

function dateChange(){
	window.location.href='meetBooking2.jsp?ReserveDate='+$('#bookingTime').val()+'&date='+$('#bookingTime').val();
}
</script>
</head>

<body>
<%
/*String ReserveDate=request.getParameter("ReserveDate");//今天的时间 */
String flag=request.getParameter("date");
if(flag == null||flag == "")
{
	flag = RequestAttribute.getDate(request);
}
String conName = RequestAttribute.getConName(request);
if(conName == null)
{
	conName = "";
}
String conMeans = RequestAttribute.getConMeans(request);
if(conMeans == null)
{
	conMeans = "";
}
String Description = RequestAttribute.getDescription(request);
if(Description == null)
{
	Description = "";
}
String ReserveDate=flag;
if(ReserveDate==null)
{
	ReserveDate="";
	
	Date date=new Date();
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	ReserveDate=sdf.format(date);
}
String bookflag=request.getParameter("bookflag");
boolean result=false;
if("success".equals(bookflag)){
result=RequestAttribute.getResult(request);
}
String Loginflag="";
Loginflag=request.getParameter("Loginflag");
if("Right".equals(Loginflag)||"WrongPassword".equals(Loginflag)||"WrongName".equals(Loginflag)){
	ReserveDate=request.getParameter("ReserveDate");	
}
//System.out.println(ReserveDate);
MeetingService ms=new MeetingService();
ArrayList<MeetingRoom> rooms=new ArrayList<MeetingRoom>();
rooms=ms.findMeetingRoom(ReserveDate);
int []states={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
int len=rooms.size();
String []DepartmentS={"","","","","","","","","","","","","","","",""};
for(int i=0;i<len;i++){
	MeetingRoom rm=rooms.get(i);
	String Department=rm.getDepartment();
	int roomID=rm.getRoomID();//1 3
	int occupyTime=rm.getOccupyTime();//2 2
	int k=(roomID-1)*4+occupyTime-1;
	if(rm.getState()==3){
		states[k]=3;
		DepartmentS[k]=Department;
	}
	if(states[k]!=3){
		if(rm.getState()==2){
			states[k]=2;
			DepartmentS[k]=Department;
		};
	}
}
%>
<form id="form" name="form" action="MeetingRoomDeal?flag=outBook" method="post">
  <div style="width:100%; height:400px;" align="center" id="meetList" name="meetList">
  	<table border="0" bgcolor="#d3d3d3" cellpadding="0" cellspacing="1" style="width:100%;" id="meetingList">
      <tr class="tr">
      <td colspan="5" style="width:100%; height:20px" align="center" class="ui-widget-header">会议室列表</td>
      </tr>
      <tr class="tr ui-state-hover" align="center">
        <td class="td ui-state-hover" style="width:20%"></td>
        <td colspan="1">B2-617</td>
        <td colspan="1">B2-708</td> 
        <td colspan="1">B2-810</td> 
        <td colspan="1">B2-811</td> 
      </tr>
      <tr class="tr" align="center">
        <td class="td ui-state-hover">上午8:30-10:00</td>
        <td class="td"><%if(states[0]==1){%><%="未预约"%><%}else if(states[0]==2){%><%=DepartmentS[0]+"(已预约)"%><%}else if(states[0]==3){%><%=DepartmentS[0]+"(已批准)"%><%} %></td>
        <td class="td"><%if(states[4]==1){%><%="未预约"%><%}else if(states[4]==2){%><%=DepartmentS[4]+"(已预约)"%><%}else if(states[4]==3){%><%=DepartmentS[4]+"(已批准)"%><%} %></td>
        <td class="td"><%if(states[8]==1){%><%="未预约"%><%}else if(states[8]==2){%><%=DepartmentS[8]+"(已预约)"%><%}else if(states[8]==3){%><%=DepartmentS[8]+"(已批准)"%><%} %></td>
<!-- 添加一个  -->
        <td class="td"><%if(states[12]==1){%><%="未预约"%><%}else if(states[12]==2){%><%=DepartmentS[12]+"(已预约)"%><%}else if(states[12]==3){%><%=DepartmentS[12]+"(已批准)"%><%} %></td>
      </tr>
      <tr class="tr" align="center">
        <td class="td ui-state-hover">上午10:30-12:00</td>
     <td class="td"><%if(states[1]==1){%><%="未预约"%><%}else if(states[1]==2){%><%=DepartmentS[1]+"(已预约)"%><%}else if(states[1]==3){%><%=DepartmentS[1]+"(已批准)"%><%} %></td>
     <td class="td"><%if(states[5]==1){%><%="未预约"%><%}else if(states[5]==2){%><%=DepartmentS[5]+"(已预约)"%><%}else if(states[5]==3){%><%=DepartmentS[5]+"(已批准)"%><%} %></td>
     <td class="td"><%if(states[9]==1){%><%="未预约"%><%}else if(states[9]==2){%><%=DepartmentS[9]+"(已预约)"%><%}else if(states[9]==3){%><%=DepartmentS[9]+"(已批准)"%><%} %></td>
<!-- 添加一个  -->        
       <td class="td"><%if(states[13]==1){%><%="未预约"%><%}else if(states[13]==2){%><%=DepartmentS[13]+"(已预约)"%><%}else if(states[13]==3){%><%=DepartmentS[13]+"(已批准)"%><%} %></td>
      </tr>
      <tr class="tr" align="center">
        <td class="td ui-state-hover">下午14:30-16:00</td>
<td class="td"><%if(states[2]==1){%><%="未预约"%><%}else if(states[2]==2){%><%=DepartmentS[2]+"(已预约)"%><%}else if(states[2]==3){%><%=DepartmentS[2]+"(已批准)"%><%} %></td>
<td class="td"><%if(states[6]==1){%><%="未预约"%><%}else if(states[6]==2){%><%=DepartmentS[6]+"(已预约)"%><%}else if(states[6]==3){%><%=DepartmentS[6]+"(已批准)"%><%} %></td>
<td class="td"><%if(states[10]==1){%><%="未预约"%><%}else if(states[10]==2){%><%=DepartmentS[10]+"(已预约)"%><%}else if(states[10]==3){%><%=DepartmentS[10]+"(已批准)"%><%} %></td>
<!-- 添加一个  -->       
      <td class="td"><%if(states[14]==1){%><%="未预约"%><%}else if(states[14]==2){%><%=DepartmentS[14]+"(已预约)"%><%}else if(states[14]==3){%><%=DepartmentS[14]+"(已批准)"%><%} %></td>
      </tr>
      <tr class="tr" align="center">
        <td class="td ui-state-hover">下午16:30-18:00</td>
        <td class="td"><%if(states[3]==1){%><%="未预约"%><%}else if(states[3]==2){%><%=DepartmentS[3]+"(已预约)"%><%}else if(states[3]==3){%><%=DepartmentS[3]+"(已批准)"%><%} %></td>
        <td class="td"><%if(states[7]==1){%><%="未预约"%><%}else if(states[7]==2){%><%=DepartmentS[7]+"(已预约)"%><%}else if(states[7]==3){%><%=DepartmentS[7]+"(已批准)"%><%} %></td>
        <td class="td"><%if(states[11]==1){%><%="未预约"%><%}else if(states[11]==2){%><%=DepartmentS[11]+"(已预约)"%><%}else if(states[11]==3){%><%=DepartmentS[11]+"(已批准)"%><%} %></td>
<!-- 添加一个  -->        
        <td class="td"><%if(states[15]==1){%><%="未预约"%><%}else if(states[15]==2){%><%=DepartmentS[15]+"(已预约)"%><%}else if(states[15]==3){%><%=DepartmentS[15]+"(已批准)"%><%} %></td>
      </tr>
    </table>
    
    <div style="width:100%;height:90%;" align="left" id="bookMes">
    <div style="height:90%;" class="ui-widget ui-state-default">
      <h3 style="margin-left:20px;">预约信息</h3>  
      <div style="float:right;margin-right:80px;"><a>预约时间: &nbsp;&nbsp;&nbsp;</a><input id="bookingTime" name="bookingTime" onchange="dateChange();" value="<%=ReserveDate%>" />&nbsp; &nbsp;</div>
      <div style="margin:20px;"><a>预约会议室: </a>
    	<select id="RoomID" name="RoomID" width="200px">
        <option>B2-617</option>
        <option>B2-708</option>
        <option>B2-810</option>
        <option>B2-811</option>
        </select>
      </div>
      <div style="float:right;margin-right:100px;"><a>联系人: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
        <input type="text" id="ConnectorName" name="ConnectorName" value="<%=conName %>"/>
      </div>
      <div style="margin:20px;"><a>预约时段: &nbsp;&nbsp;</a>
    	<select id="OccupyTime" name="OccupyTime" width="200px">
        <option>8:30-10:00</option>
        <option>10:30-12:00</option>
        <option>14:30-16:00</option>
        <option>16:30-18:00</option>
        </select>
      </div>
      <div style="float:right;margin-right:100px;"><a>联系方式: &nbsp;&nbsp;</a>
        <input type="text" id="ConnectMeans" name="ConnectMeans" value="<%=conMeans %>"/>
      </div>
      <div style="margin:20px;"><a>参会人数: &nbsp;&nbsp;</a>
        <select id="AttenderNumber" name="AttenderNumber" width="200px">
        <option>20人以下</option>
        <option>20-30人</option>
        <option>30-40人</option>
        </select>
      </div>
      <div style="margin:20px;"><a>备注: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
        <input type="text" id="Description" name="Description" value="<%=Description %>"/>
        <input type="hidden" name="ReserverName" value="<%=userName%>">
        <input type="hidden" name="Department" value="<%=userDepartment%>">
      </div>
      <div style="margin:20px;float: right;">
      <input type="button" value="返回" id="submit2" name="submit2" onclick="save2()"/>
      </div>
      <div style="margin:20px;float: right;">
      <input type="button" value="提交" id="submit3" name="submit3" onclick="save()"/>
      </div>
      <%if(result){%>
       <div style="margin:20px;float: right;">
      <span style="color: red;" >*已预约</span>
      </div>
      <% }else if("fail".equals(bookflag)){%>
      <div style="margin:20px;float: right;">
      <span style="color: red;" >*预约无效</span>
      </div>
      <%}%>
    </div>
    </div>
    <br/><br/>
     <% if(!show){%> <span style="color:red; ">*预 约 会 议 室 请 登 录</span><% }%><br>
     <% if("WrongName".equals(Loginflag)||"WrongPassword".equals(Loginflag)){%><span style="color:red; ">密码错误</span><%} %>
    <div id="login" >
    
    <div style="wdith:300px;border:solid 1px #eee; display:block">
   	用 户 名： 	<input name="userNumber" type="text" style="width:200px" /><br/>
   	密&nbsp;&nbsp;&nbsp;&nbsp;码：&nbsp;	<input name="userPassword" type="password"  style="width:200px" /><br/><br/>
    <input id="log" type="button" value="登录" style="30px;" onclick="document.form.action='UserDeal?flag=check_meeting&ReserveDate=<%=ReserveDate %>';document.form.submit();">
    </div>
  </div>
</form>

<script>
	$("#submit1").button();
	$("#submit2").button();
	$("#submit3").button();
	$("#log").button();
	$("input#bookingTime").datepicker({
		dateFormat: "yy-mm-dd"
	});
</script>
</body>
</html>